<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>首页 - Index</title>
</head>
<body>
<h1>进入首页</h1>
<hr>
<img style="width: 475px; height: 272px" src="/images/熊猫.gif">

<h1>动态获取项目名</h1>
<hr>
方法一：pageContext.request.contextPath=${pageContext.request.contextPath}
<br>
方法二：request.getContextPath()=<%=request.getContextPath()%>

<h1>加载项目 resources 目录下的资源</h1>
<hr>
<img style="width: 300px; height: 300px" src="/images/灯泡.gif">

<h1>从 Request 对象中获取各种路径信息</h1>
<hr>
<%
    String path = request.getContextPath();
    out.println("<br> path=" + path);

    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
    out.println("<br> basePath=" + basePath);

    String remoteAddress = request.getRemoteAddr();
    out.println("<br> remoteAddr=" + remoteAddress);

    String servletPath = request.getServletPath();
    out.println("<br> servletPath=" + servletPath);

    String realPath = request.getRealPath("/");
    out.println("<br> realPath=" + realPath);

    String remoteUser = request.getRemoteUser();
    out.println("<br> remoteUser=" + remoteUser);

    String requestURI = request.getRequestURI();
    out.println("<br> requestURI=" + requestURI);
%>
</body>
</html>
